package cn.fz.learn02.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum CodeEnum {
    SUCCESS(0, "成功"),
    FAIL(1, "失败"),
    EXCEPTION(999, "接口异常");

    public final Integer code;
    public final String message;

    public static CodeEnum getEnumByCode(Integer code) {
        for (CodeEnum codeEnum : CodeEnum.values()) {
            if (codeEnum.code.equals(code)) {
                return codeEnum;
            }
        }
        return null;
    }

    public static CodeEnum getEnumByMessage(String message) {
        for (CodeEnum codeEnum : CodeEnum.values()) {
            if (codeEnum.message.equals(message)) {
                return codeEnum;
            }
        }
        return null;
    }
}
